<template>
  <footer
    ref="footerRef"
    class="app-footer"
    :style="footerStyle"
  >
    <div class="footer-content">
      <!-- 社交平台图标 -->
      <div class="social-section">
        <div
          v-for="platform in platforms"
          :key="platform.name"
          class="social-icon"
        >
          <el-tooltip effect="dark" :content="platform.tooltip" placement="top">
            <img :src="platform.icon" :alt="platform.name" />
          </el-tooltip>
        </div>
      </div>

      <!-- 品牌文案 -->
      <div class="footer-text">
        <p>© 2025 Volcanic Coffee. All rights reserved.</p>
        <p>用一杯好咖啡连接人与土地的温度。</p>
      </div>

    </div>
  </footer>
</template>

<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue'
import { ArrowUp } from '@element-plus/icons-vue'

const isVisible = ref(true)
const isScrollingDown = ref(true)
const footerRef = ref(null)
let lastScrollY = window.scrollY

// 平台信息
const platforms = [
  { name: '微博', icon: '/weibo.jpg', tooltip: '微博：@VolcanicCoffee' },
  { name: 'Bilibili', icon: '/bilibili.jpg', tooltip: 'B站：Volcanic 咖啡官方频道' },
  { name: '小红书', icon: '/xiaohongshu.jpg', tooltip: '小红书：Volcanic 咖啡生活志' },
  { name: 'Instagram', icon: '/instagram.jpg', tooltip: 'Instagram: @volcanic.coffee' },
]

// 滚动方向判断
function handleScroll() {
  const currentY = window.scrollY
  isScrollingDown.value = currentY > lastScrollY
  lastScrollY = currentY
}

// 动态样式控制
const footerStyle = computed(() => {
  if (!isVisible.value) {
    return {
      opacity: 0,
      transform: 'translateY(40px)',
      pointerEvents: 'none',
    }
  }
  return isScrollingDown.value
    ? {
        opacity: 1,
        transform: 'translateY(0)',
        pointerEvents: 'auto',
      }
    : {
        opacity: 0,
        transform: 'translateY(40px)',
        pointerEvents: 'none',
      }
})

// 监听进入视口 + 滚动方向
let observer
onMounted(() => {
  observer = new IntersectionObserver(
    ([entry]) => {
      isVisible.value = entry.isIntersecting
    },
    { threshold: 0.1 }
  )
  if (footerRef.value) observer.observe(footerRef.value)

  window.addEventListener('scroll', handleScroll)
})

onUnmounted(() => {
  if (footerRef.value && observer) observer.unobserve(footerRef.value)
  window.removeEventListener('scroll', handleScroll)
})
</script>

<style scoped>
.app-footer {
  overflow: hidden;
  background: #fff8f1;
  color: #4a2e18;
  padding: 60px 20px 40px;
  text-align: center;
  transition: opacity 0.6s ease, transform 0.6s ease;
  position: relative;
  border-top: none;
  box-shadow: inset 0 8px 16px -12px rgba(0, 0, 0, 0.08); /* 顶部内阴影 */
  z-index: 1;
    border-top: 1px solid rgba(74, 46, 24, 0.1); /* 咖啡棕淡线 */
}
.app-footer::before {
  content: '';
  position: absolute;
  top: -20px;
  left: 0;
  width: 100%;
  height: 40px;
  background: linear-gradient(to bottom, rgba(255, 248, 241, 0), #fff8f1);
  z-index: -1;
}

.footer-content {
  max-width: 1000px;
  margin: 0 auto;
  position: relative;
  padding-top: 20px;
}

.social-section {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 20px;
}
.social-icon img {
  width: 32px;
  height: 32px;
  cursor: pointer;
  transition: transform 0.3s ease;
  border-radius: 100%;
}
.social-icon img:hover {
  transform: scale(1.2);
}

.footer-text p {
  font-size: 14px;
  margin: 4px 0;
  color: #6b4a2d;
}


</style>
